<template>
    <div class="wrapper" :style="activeWrapper" @click="handleClick">
      <div class="title">{{title}}</div>
      <div class="divider"/>
      <div class="content">
        {{content}}
      </div>
      <div class="change">
        <el-button @click.stop="handleChange" :disabled="changeDisabled" :loading="changeLoading"
                   size="mini" type="text">{{changeText}}</el-button>
      </div>
      <div class="default">
        <el-button @click.stop="handleToDefault" size="mini" type="text">设为默认</el-button>
      </div>
    </div>
</template>

<script>
export default {
  name: 'AddressItem',
  props: {
    active: {
      require: false,
      type: Boolean,
      default: false
    },
    address: {
      require: true,
      type: Object
    },
    changeText: {
      require: false,
      type: String,
      default: '修改地址'
    },
    changeDisabled: {
      require: false,
      type: Boolean,
      default: false
    },
    changeLoading: {
      require: false,
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleClick () {
      this.$emit('click', this.address)
    },
    /**
     * 修改地址
     */
    handleChange () {
      this.$emit('change', this.address)
    },
    /**
     * 设置为默认地址
     */
    handleToDefault () {
      this.$emit('default', this.address)
    }
  },
  computed: {
    activeWrapper () {
      return this.active ? {
        borderColor: 'red'
      } : {}
    },
    title () {
      const address = this.address
      return address['provinceName'] + address['cityName'] + '(' + address['username'] + '收)'
    },
    content () {
      const address = this.address
      return address['countyName'] + address['detail'] + ' ' + address['phone']
    }
  }
}
</script>

<style scoped lang="scss">

  .wrapper:hover{
    border-color: red;

    .change{
      display: block;
    }

    .default{
      display: block;
    }

  }

  .wrapper{
    width: 100%;
    height: 100px;
    padding: 8px 20px;
    border: 2px solid #666666;
    border-radius: 4px;
    cursor: pointer;
    position: relative;

    .title{
      text-align: left;
    }

    .divider{
      width: 100%;
      height: 0.4px;
      margin: 6px 0;
      background: #999999;
    }

    .content{
      text-align: left;
      width: 100%;
      height: 40px;
      overflow: hidden;
    }

    .change{
      position: absolute;
      bottom: 0;
      right: 0;
      margin-right: 8px;
      background: white;
      display: none;
    }

    .default{
      position: absolute;
      top: 0;
      right: 0;
      margin-right: 8px;
      background: white;
      display: none;
    }

  }

</style>
